import { getMenuList } from '@/api/app'
const state = {
  menuList: [],
  opended: false
}

const mutations = {
  SET_MENU_LIST(state, menuList) {
    state.menuList = menuList
  },
  togleSidebar(state) {
    state.opended = !state.opended
  }
}

const actions = {
  getMenuList({ commit }) {
    getMenuList().then((res) => {
      // console.log(res)
      commit('SET_MENU_LIST', res.data)
    })
  }
}

const getters = {
  hasChild(state) {
    return state.menuList.filter((item) => item.children)
  },
  noChild(state) {
    return state.menuList.filter((item) => !item.children)
  }
}

export default {
  namespaced: true,
  state,
  mutations,
  actions,
  getters
}
